package marinagosson.ti.trabalho.database;

import java.sql.SQLException;

import marinagosson.ti.trabalho.bean.Cliente;
import marinagosson.ti.trabalho.bean.OS;
import marinagosson.ti.trabalho.bean.Prestador;
import marinagosson.ti.trabalho.bean.Status;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;

public class DAOFactory {

	private static Dao<Cliente, String> clienteDAO;
	private static Dao<Prestador, String> prestadorDAO;
	private static Dao<OS, String> osDAO;
	private static Dao<Status, String> statusDAO;

	public static Dao<Cliente, String> getClienteDao() {
		if (clienteDAO == null) {
			try {
				clienteDAO = DaoManager.createDao(
						ConnectionFactory.getConnection(), Cliente.class);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return clienteDAO;
	}

	public static Dao<Prestador, String> getPrestadorDao() {
		if (prestadorDAO == null) {
			try {
				prestadorDAO = DaoManager.createDao(
						ConnectionFactory.getConnection(), Prestador.class);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return prestadorDAO;
	}

	public static Dao<OS, String> getOSDao() {
		if (osDAO == null) {
			try {
				osDAO = DaoManager.createDao(ConnectionFactory.getConnection(),
						OS.class);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return osDAO;
	}

	public static Dao<Status, String> getStatusDao() {
		if (statusDAO == null) {
			try {
				statusDAO = DaoManager.createDao(
						ConnectionFactory.getConnection(), Status.class);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return statusDAO;
	}

}